package com.none.staff.view.activitys

import android.annotation.SuppressLint
import android.support.constraint.ConstraintLayout
import android.support.v4.view.ViewPager
import android.view.Gravity
import android.view.View
import android.widget.Button
import android.widget.ImageView
import com.none.staff.R
import com.none.staff.managers.SharePreferenceManager
import com.none.staff.utils.Constants
import com.none.staff.view.adapter.GuideAdapter
import com.peter.baselibrary.utils.AppUtils
import com.peter.electronicmall.base.BaseActivity
import java.util.*

class GuideActivity : BaseActivity() {

    var viewPager: ViewPager? = null
    var viewList: ArrayList<ImageView> = ArrayList()
    override fun getLayoutId(): Int {
        return R.layout.activity_guide
    }

    override fun initView() {
        val adapter = GuideAdapter(this, viewList)
        val openButton: Button = findViewById(R.id.button)
        openButton.setOnClickListener {
            SplashActivity.startSplashActivity(this@GuideActivity)
            finish()
        }
        openButton.background.alpha = 80
        viewPager = findViewById(R.id.viewPager)
        viewPager?.adapter = adapter
        viewPager?.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(i: Int, v: Float, i1: Int) {

            }

            override fun onPageSelected(i: Int) {
                if (i == viewList.size - 1) {
                    openButton.visibility = View.VISIBLE
                } else {
                    openButton.visibility = View.GONE
                }
            }

            override fun onPageScrollStateChanged(i: Int) {

            }
        })
    }

    @SuppressLint("InflateParams")
    override fun initData() {
        val imageViewOne = ImageView(this)
        imageViewOne.setImageResource(R.mipmap.guide_01)
        val imageViewTwo = ImageView(this)
        imageViewTwo.setImageResource(R.mipmap.guide_02)
        val imageViewThree = ImageView(this)
        imageViewThree.setImageResource(R.mipmap.guide_03)
        viewList.add(imageViewOne)
        viewList.add(imageViewTwo)
        viewList.add(imageViewThree)
        val preferenceManager = SharePreferenceManager(this)
        preferenceManager
                .getSharedPreferences(Constants.SP_APPLICATION_VERSION)
                .putString(Constants.SP_APK_VERSION, AppUtils.getVersion(this))
    }

    override fun onReConnect() {

    }
}
